<?php
namespace app\front\service\v2;

class CommonFunction
{
    //自定义菜单创建
    public function menu_create()
    {
        //获取本公众号AccessToken
        $access_token=getAccessToken();
        //自定义菜单请求发送地址
        $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token={$access_token}";
        $post = ' {
		     "button":[
		      {
		           "name":"附近商家",
                   "type":"view",
		           "url":"http://www.zfshlm.com/098f6bcd4621d373cade4e832627b4f6/zfshlm_5_0/public/index.php/front/v2.ShowController/showStore"
            
		      },
 {
		           "name":"个人中心",
                   "type":"view",
		            "url":"http://www.zfshlm.com/098f6bcd4621d373cade4e832627b4f6/zfshlm_5_0/public/index.php/front/v2.PersonalCenterController/PersonalCenter"
            
		      },
 {
		           "name":"商家入口",
                   "type":"view",
		            "url":"http://www.zfshlm.com/8bf462226df7aa80f0ca1313f10cea95/zfshlm/public/index/index/index"
            
		      }

            
 ]
		 }';
        // "url":"http://2637716492.xyz.1048.url-test.com//zfshlm/public/index/index/index"
        //curl初始化
        $outopt= https_request($url,$post);
        echo $outopt['errmsg'];
    }
    
    //自定义菜单查询
    public function menu_select()
    {
        $access_token = $this->getAccessToken();
        $url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token={$access_token}";
        return https_request($url);
    }
    
    //自定义菜单删除
    public function menu_delete()
    {
        $access_token = $this->getAccessToken();
        $url = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token={$access_token}";
        return https_request($url);
    }
    
    
    function sendMsgALL(){
        //1.获取access——token
        $access_token=getAccessToken();
        //2.组装群发接口数据
        $url="https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token=".$access_token;
        //         $array=array(//群发纯文本
        //             'touser'=>'oIJy50aO4UI7pBi0Nw-2nUO6Qgmw',//发送的目标用户的openid
        //             'text'=>array('content'=>'chulu '),//文本内容
        //             'msgtype'=>'text'//消息类型
        //         );
        
        $array=array(//群发单图文
            'touser'=>'oTZZ4w9WAz0fEWyIj6ZeKQvFR2ek',//发送的目标用户的openid
            'mpnews'=>array('media_id'=>'qI6_Ze_6PtV7svjolgs-rN6stStuHIjs9_DidOHaj0Q-mwvBelOXCFZiq2OsIU-p'),//文本内容
            'msgtype'=>'mpnews'//消息类型
        );
        //3.将数组->json
        $postJson=json_encode($array);
        $res=https_request($url,$postJson);
        print_r($res);
    }
    
    //实现临时二维码,扫描此码直接进入公众号关注页面
    public function getTimeQrCode(){
        //1.获取ticket票据
        //全局票据access_token 网页授权access_token 微信js-SDKjsapi_ticket
        $access_token=getAccessToken();
        $url= "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=".$access_token;
        //例：{"expire_seconds": 604800, "action_name": "QR_STR_SCENE", "action_info": {"scene": {"scene_str": "test"}}}
        $postArr=array(
            'expire_seconds'=> 604800,
            'action_name'=> "QR_STR_SCENE",
            'action_info'=> array(
                'scene'=>array('scene_str'=>2000),
            ),
        );
        $postJson=json_encode( $postArr);
        $res=https_request($url,$postJson);
        $ticket=$res['ticket'];
        //2.使用ticket获取二维码图片
        $url="https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=".urlencode($ticket);
       https_request($url);
        echo "临时二维码";
        echo "<img src='".$url."'/>";
    }
    
    //实现永久二维码,扫描此码直接进入公众号关注页面（永久有效）
    public function getForeverQrCode(){
        //1.获取ticket票据
        //全局票据access_token 网页授权access_token 微信js-SDKjsapi_ticket
        $access_token=getAccessToken();
        $url= "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=".$access_token;
        //例：{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": 123}}}
        //         或者也可以使用以下POST数据创建字符串形式的二维码参数：
        //         {"action_name": "QR_LIMIT_STR_SCENE", "action_info": {"scene": {"scene_str": "test"}}}
        $postArr=array(
            'action_name'=> "QR_LIMIT_SCENE",
            'action_info'=> array(
                'scene'=>array('scene_id'=>5000),
            ),
        );
        $postJson=json_encode( $postArr);
        $res=https_request($url,$postJson);
        $ticket=$res['ticket'];
        //2.使用ticket获取二维码图片
        $url="https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=".urlencode($ticket);
        https_request($url);
        echo "永久二维码";
        echo "<img src='".$url."'/>";
    }
}

